import requests
import hashlib
def make_md5(text):
    """
    Md5加密 只能加密字符串
    :param text:  需要加密的内容，必须是个字符串
    :return:
    """
    m = hashlib.md5() # 创建一个 md5加密工具
    m.update(str(text).encode(encoding='utf-8'))
    res = m.hexdigest()  # 生成加密后的内容
    return res



s = requests.session()
url = 'http://114.132.200.42:3456/user/login'
data = {
    "username":"123456lk",
    "password":make_md5('1524535267'),
    "checkcode":"1234"
}

res = s.post(url = url,data = data).json()
print(res)

get_userid = res['userId']
get_usertoken = res['userToken']



url = 'http://114.132.200.42:3456/task/info'
data = {
    "title":"nidayea"
}
head = {"userId":get_userid,"userToken":get_usertoken}
res_task = s.post(url = url,data = data,headers=head)
print(res_task.json())


url = 'http://114.132.200.42:3456/task/info'
data = {
    "status":"0"
}

res = s.get(url=url,params=data,headers=head)
print(res.json())

# 文件上传
imgurl = "http://114.132.200.42:3456/user/uploal_action"
img = [
    ('pic',('get.jpg',open('kenan.jpg','rb')))
]
res = s.post(url=imgurl,headers=head,files = img)
print(res.json())

